<?php
require_once('lib/diy.php');
require_once('lib/model.php');

$id = $_GET['id'];
$smarty = new Smarty_Diycity();
$problems = new DiyModel("problems");
$update = new DiyModel("updates");

$updates = $update->find('all', array('conditions' => array('problem_id' => $id),
				      'order' => 'id asc'));
$problem = $problems->find('all', array('conditions' => array('id' => $id)));
$problem = $problem[0];

$full_address = $problem['address1'] ." ". $problem['address2'] ." ". $problem['address3'];

$lat = $problem['lat'];
$lng = $problem['lng'];

if (file_exists("photos/" . $id)) {
  $smarty->assign('img_href', $id);
}

$update_img = array();
if (sizeof($updates) > 0) {

  foreach ($updates as &$item) {
    $path = $item['problem_id'] . '_' . $item['id'];
    if ( file_exists("photos/" . $path) )
      $item['img'] = $path;
  }

  $smarty->assign('updates', $updates);
}

$smarty->assign('problem_id', $id);
$smarty->assign('address', $full_address);

$smarty->assign('address2', $problem['address2']);

$smarty->assign('state', $problem['state']);

$smarty->assign('subject', $problem['subject']);
$smarty->assign('details', $problem['details']);
$smarty->assign('reporter', $problem['reporter']);
$smarty->assign('category', $problem['category']);
$modified_time = explode(' ', $problem['modified_time']);
$modified_time = $modified_time[0];
$smarty->assign('modified', $modified_time);
$smarty->assign('time', $problem['created_time']);
$smarty->assign('service_type', $problem['service_type']);
if (ADMIN) {
  $smarty->assign('email', $problem['email']);
 }


$smarty->assign('lat', $lat);
$smarty->assign('lng', $lng);

$smarty->display('view_report.tpl');
?>
